Fix debug mode for vector/list and cleanup tests git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290657 91177308-0d34-0410-b5e6-96231b3b80d8 
diff --git a/include/vector b/include/vector index 3dae3b5..0e014d4 100644 --- a/include/vector +++ b/include/vector 
@@ -738,9 +738,9 @@    void swap(vector&)  #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT; + _NOEXCEPT_DEBUG;  #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||  __is_nothrow_swappable<allocator_type>::value);  #endif   @@ -757,6 +757,7 @@    private:  _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);  void allocate(size_type __n);  void deallocate() _NOEXCEPT;  _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; @@ -786,21 +787,7 @@  _LIBCPP_INLINE_VISIBILITY  void __destruct_at_end(pointer __new_last) _NOEXCEPT  { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __c_node* __c = __get_db()->__find_c_and_lock(this); - for (__i_node** __p = __c->end_; __p != __c->beg_; ) - { - --__p; - const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->base() > __new_last) - { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); - } - } - __get_db()->unlock(); -#endif + __invalidate_iterators_past(__new_last);  size_type __old_size = size();  __base::__destruct_at_end(__new_last);  __annotate_shrink(__old_size); @@ -1415,6 +1402,7 @@  allocate(__recommend(__new_size));  __construct_at_end(__first, __last, __new_size);  } + __invalidate_all_iterators();  }    template <class _Tp, class _Allocator> @@ -1436,6 +1424,7 @@  allocate(__recommend(static_cast<size_type>(__n)));  __construct_at_end(__n, __u);  } + __invalidate_all_iterators();  }    template <class _Tp, class _Allocator> @@ -1679,8 +1668,9 @@  "vector::erase(iterator) called with a non-dereferenceable iterator");  difference_type __ps = __position - cbegin();  pointer __p = this->__begin_ + __ps; - iterator __r = __make_iter(__p);  this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); + this->__invalidate_iterators_past(__p-1); + iterator __r = __make_iter(__p);  return __r;  }   @@ -1692,12 +1682,17 @@  _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,  "vector::erase(iterator, iterator) called with an iterator not"  " referring to this vector"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "vector::erase(iterator, iterator) called with an iterator not" + " referring to this vector");  #endif  _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");  pointer __p = this->__begin_ + (__first - begin()); - iterator __r = __make_iter(__p); - if (__first != __last) + if (__first != __last) {  this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); + this->__invalidate_iterators_past(__p - 1); + } + iterator __r = __make_iter(__p);  return __r;  }   @@ -2018,9 +2013,9 @@  void  vector<_Tp, _Allocator>::swap(vector& __x)  #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT + _NOEXCEPT_DEBUG  #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||  __is_nothrow_swappable<allocator_type>::value)  #endif  { @@ -2103,6 +2098,28 @@  #endif // _LIBCPP_DEBUG_LEVEL >= 2  }   + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#else + ((void)__new_last); +#endif +} +  // vector<bool>    template <class _Allocator> class vector<bool, _Allocator>; @@ -2367,7 +2384,7 @@  #if _LIBCPP_STD_VER >= 14  _NOEXCEPT;  #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  __is_nothrow_swappable<allocator_type>::value);  #endif  static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } @@ -2898,6 +2915,7 @@  }  _VSTD::fill_n(begin(), __n, __x);  } + __invalidate_all_iterators();  }    template <class _Allocator> @@ -3159,7 +3177,7 @@  #if _LIBCPP_STD_VER >= 14  _NOEXCEPT  #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||  __is_nothrow_swappable<allocator_type>::value)  #endif  {